#include <iostream>
#include <string>
#include <sstream>
#include <iterator>
#include <map>
#include <vector>
#include <sstream>
#include <algorithm>
#include <functional>
#include <cctype>
#include <cstdlib>
#include <stdio.h>
#include <string.h>



using namespace std;
typedef multimap<short, string> Dict;
typedef map<string, string> Analogus;
typedef pair<string, string> CD;
typedef vector<CD> Code;
char decoded_chars[26];
static short decoded_chars_count = 0;

// trim from start
static inline std::string &ltrim(std::string &s) {
        s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
        return s;
}

// trim from end
static inline std::string &rtrim(std::string &s) {
        s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
        return s;
}

// trim from both ends
static inline std::string &trim(std::string &s) {
        return ltrim(rtrim(s));
}

const string& print_second(const pair< string, string >& data) {
	return data.second;	
}

void print_code(const vector<CD> & line) {
	transform( line.begin(), line.end(), ostream_iterator<const string>(cout, " " ), print_second);
	cout << endl;		
}

void analogous_code(const string& word, string& code) {
	code.clear();
	string::const_iterator w = word.begin();
	map<char, short> hash;
	map<char, short>::iterator it;
	while(w != word.end()) {
		it = hash.find(*w);
		if(it == hash.end()) {
			pair<char, short>p(*w, 1);
			hash.insert(hash.end(), p);
		} else {
			it->second++;
		}
		w++;
	}
	for(short i =0; i < word.size(); i++) {
			code += hash[word[i]];
	}
}

bool is_analogous_code(const string& encrypted,  const string& code_e, const pair<string,string>& code) {
	if(code_e == code.second) {
		short count = 0;
		for(short i =0; i < encrypted.size(); i++) {
			char d = decoded_chars[encrypted[i]-'a'];
			if(d == 0)
				count++;
			else if(d != code.first[i]) {
				return false;
			} 
		}
		if(count == encrypted.size())
			return false;
		return true;
	}
	return false;
}

void update_mapping(const string& C, const string& P) {
	for(size_t i = 0; i < C.size(); i++) {
		if(decoded_chars[ C[i]-'a'] == 0) {
			decoded_chars[C[i]-'a'] = P[i];
			decoded_chars_count++;
		}
	}
}

bool decode_from_mapping(const string& C, string& P) {
	string temp;
	for(size_t i = 0; i < C.size(); i++) {
		if(decoded_chars[C[i]-'a'] != 0) {
			temp+= decoded_chars[C[i]-'a'];
		} else {
			return false;	
		}
	}
	P = temp;
	return true;
}

void decode(vector<CD>& line) {
	vector<CD>::iterator cd = line.begin();
	while(cd != line.end()) {
		decode_from_mapping(cd->first, cd->second);
		cd++;
	} 
}

void decode(const Dict & words, const Analogus& codes,vector<CD>& line) {
	bool decode_loop = true;
	bool new_loop = true;
	vector<CD>::iterator cd = line.begin();
	while(cd != line.end()) {
		if(new_loop == true)
			decode_loop = false;
		if((*cd).second[0] == '*') {
			short key = (*cd).first.size();
			pair<Dict::const_iterator, Dict::const_iterator> range = words.equal_range(key);
			Dict::const_iterator p = range.first;
			string code;
			analogous_code((*cd).first, code);
			if(decode_from_mapping(cd->first, cd->second) == true) {
				decode_loop = true;
			} else if((++p == range.second) && (code == codes.find(range.first->second)->second)) {
					decode_loop = true;
					cd->second = range.first->second;
					update_mapping(cd->first, cd->second);
			} else {
				for(p = range.first; p != range.second; p++) {
					Analogus::const_iterator it = codes.find(p->second);
					if(it != codes.end() && is_analogous_code((*cd).first, code, *it)) {
						decode_loop = true;
						cd->second = p->second;
						update_mapping(cd->first, cd->second);
						break;
					}
				}
			}
		}
		cd++;

		if(decode_loop == true && cd == line.end()) {
			cd = line.begin();
			new_loop = true;
			continue;
		}
		new_loop = false;	
	}
}

/* main
 *  * */
int main() {
	short size  = 0;
	Dict words;
	Analogus codes;
	//memset(decoded_chars, 0, 26);
	string word;
	stringstream token;
	//cout << "size " << size << endl;
	cin >> size;
	scanf("%*[^\n]");
	getc(stdin);
	string s;
	while(size-- > 0) {
		token.clear();
		getline(cin, s);
		token << s;
		token >> word;
		string code;
		analogous_code(word, code);
		pair<short, string> l(word.size(), word);
		words.insert(words.end(), l);
		pair<string, string> w(word, code);
		codes.insert(codes.end(), w);
	}
	do {
		memset(decoded_chars, 0, 26);
		getline(cin, s);
		trim(s);
		if(s.size() > 0) {
			Code line;
			token.clear();
			//cout << s << endl;
			token << s;
			while(token.eof() != true) {
				token >> word;
				CD p(word, string(word.size(), '*'));
				line.push_back(p);
			}
			if(decoded_chars_count < 26)
				decode(words, codes, line);
			else
				decode(line);
			print_code(line);
		}
	} while(cin.eof() == false);
	return 0;
}
